import 'package:get/get.dart';
import 'package:yp/services/api.dart';
import 'state.dart';

class SearchMemberLogic extends GetxController {
  final state = SearchMemberState();

  @override
  void onReady() {
    super.onReady();
    // int phone = Get.arguments['phone'];
    if(Get.arguments != null ){
      state.controller.text = Get.arguments['phone'].toString();
      searchMember();
    }
  }

  //选中当前会员并返回上级页面
  // void selectMember(data) {
  void selectMember() {
    state.selectMemberData = state.memberData;
    Get.back(result: state.selectMemberData);
  }

  //会员搜索
  void searchMember(){
    var params = {
      "mobile":state.controller.text,
      "usr_num_id":null,
      "usr_type": 1
    };
    Api.searchMember(params).listen((event) {
      print(event["code"]);
      state.searchResultIshow = true;
      if(event["code"] == 0){
        state.memberData = event;
        state.searchResult = true;
        update();
      }else{
        state.searchResult = false;
        update();
      }
    });
  }
}
